package com.xbongbong.sys.model.impl;

import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.sys.domain.dao.CoverRoleDao;
import com.xbongbong.sys.domain.entity.CoverRoleEntity;
import com.xbongbong.sys.domain.entity.RoleEntity;
import com.xbongbong.sys.model.CoverRoleModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 *
 * @author kaka
 * @version v1.0
 * @date 2019/5/7 20:28
 * @since v1.0
 */
@Service("coverRoleModel")
public class CoverRoleModelImpl implements CoverRoleModel {

    @Resource
    private CoverRoleDao coverRoleDao;

    @Override
    public Integer insert(CoverRoleEntity entity){
        Integer now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);

        return coverRoleDao.insert(entity);
    }

    @Override
    public Integer update(CoverRoleEntity entity){
        entity.setUpdateTime(DateUtil.getInt());

        return coverRoleDao.update(entity);
    }

    @Override
    public Integer save(CoverRoleEntity entity){

        if(entity.getId() == null || Objects.equals(0, entity.getId())) {
            return insert(entity);
        }
        return update(entity);
    }

    @Override
    public Integer deleteByKey( Integer key,  String corpid){
        return coverRoleDao.deleteByKey(key , corpid);
    }

    @Override
    public CoverRoleEntity getByKey( Integer key,  String corpid){
        return coverRoleDao.getByKey(key , corpid);
    }

    @Override
    public CoverRoleEntity getByRoleId(Integer roleId, String corpid) {
        return coverRoleDao.getByRoleId(roleId, corpid);
    }

    @Override
    public List<CoverRoleEntity> getByRoleIdIn(Collection<Integer> roleIdIn, String corpid) {
        Map<String, Object> param = new HashMap<>(8);
        param.put("corpid", corpid);
        param.put("roleIdIn", roleIdIn);
        param.put("del", 0);
        return findEntitys(param);
    }

    @Override
    public List<CoverRoleEntity> findEntitys(Map<String ,Object>  param){
        return coverRoleDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String ,Object>  param){
        return coverRoleDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public void updateBatchPermissions(List<CoverRoleEntity> CoverRoleEntityList, String corpid) {
        coverRoleDao.updateBatchPermissions(CoverRoleEntityList, corpid);
    }
}
